<template>
    <view>
        <navigator
            class="UgobackFix"
            hoverClass="none"
            :openType="pages.length == 1 ? 'switchTab' : 'navigateBack'"
            :style="'top:' + nTop + 'px'"
            :url="pages.length == 1 ? '/pages/index/index4' : ''"
        >
            <view class="i ico">{{ pages.length == 1 ? '' : '' }}</view>
        </navigator>
        <scroll-view
            @refresherrefresh="onPullDownRefresh"
            @scroll="binnd_scroll"
            @scrolltolower="onReachBottom"
            :enableBackToTop="true"
            :enableFlex="true"
            lowerThreshold="300"
            :refresherEnabled="true"
            :refresherTriggered="triggered"
            :scrollTop="scrolltopNum_index"
            :scrollWithAnimation="true"
            :scrollY="true"
            :style="'height:-webkit-calc(100vh + ' + nTop + 'px);'"
        >
            <view class="anli_BN">
                <image mode="widthFix" :src="banner"></image>
            </view>
            <view class="anli" :style="'--color:' + color + ';--rgbcolor:' + rgbcolor">
                <block v-if="LIST.length > 0" v-for="(dl, trend_idx) in LIST" :key="trend_idx">
                    <view class="dl" v-for="(item, trend_idx2) in dl" :key="trend_idx2">
                        <view class="dt">
                            <navigator class="a" hoverClass="none" :url="'/hnPages/hn_detail/hn_detail?id=' + item.hn.admid" v-if="item.hn.admid > 0">
                                <image mode="aspectFill" :src="item.hn.path_s_url"></image>
                            </navigator>
                            <view class="a" v-else>
                                <image mode="aspectFill" :src="item.hn.path_s_url"></image>
                            </view>
                        </view>

                        <view class="dd">
                            <view class="h2">
                                <text class="font">{{ item.title }}</text>
                            </view>
                            <view class="h3">{{ item.title2 }}</view>
                            <rich-text class="h1" :nodes="item.content"></rich-text>
                            <view class="p" v-if="item.piclist.length > 1">
                                <image
                                    @tap="zoom9Fn"
                                    :data-cur="item2"
                                    :data-idx="trend_idx"
                                    :data-idx2="trend_idx2"
                                    mode="aspectFill"
                                    :src="item2"
                                    v-for="(item2, index) in item.piclist"
                                    :key="index"
                                ></image>
                            </view>
                            <view class="h1" v-else>
                                <image @tap="zoom9Fn" :data-cur="item.piclist[0]" :data-idx="trend_idx" :data-idx2="trend_idx2" mode="widthFix" :src="item.piclist[0]"></image>
                            </view>
                        </view>

                        <view class="agree">
                            <view class="span time">{{ item.addtime }}</view>
                            <view @tap="agreeFn" :class="'i' + item.agree.class" :data-id="item.id" :data-idx="trend_idx" :data-idx2="trend_idx2">
                                <text class="font ico"></text>
                                <text class="font">
                                    <text class="b agreefly" :style="'display:' + item.agree.fly + ';'">+1</text>
                                    <text class="span">{{ item.agree.num }}</text>
                                </text>
                            </view>
                            <block v-if="item.agree.num > 0">
                                <view class="j"></view>
                                <view class="em">
                                    <image
                                        @tap="uidFn"
                                        :data-uid="item3.uid"
                                        mode="aspectFill"
                                        :src="item3.photo_s_url"
                                        v-for="(item3, index) in item.agree.ulist"
                                        :key="index"
                                    ></image>
                                </view>
                            </block>
                        </view>
                    </view>
                </block>
                <view class="nodata" v-if="li_nodata && LIST.length == 0">
                    <image mode="aspectFit" src="/static/res/img/nodata.png"></image>
                    暂无符合条件的内容　
                    <text @tap="nodatabackFn" data-sokind="default" :style="'color:' + color">返回</text>
                </view>
                <view class="loading" v-if="loading_flag">
                    <image class="loading_ico" src="/static/res/img/loading_ico.svg" v-if="loading_ico_flag"></image>
                    <text>{{ loading_str }}</text>
                </view>
            </view>
            <view class="blank">　</view>
        </scroll-view>
        <view @tap="backtopFn" class="backtop fadeInUp" data-id="index" :style="'color:' + color" v-if="backtop_flag">
            <text class="ico icon-backtop"></text>
            顶部
        </view>
    </view>
</template>
<script>
var t;
var a = require('../../@babel/runtime/helpers/defineProperty');
var e = require('../../res/www.a9a.cn.js');
var app = getApp();
var n = 2;
var o = true;
export default {
    data() {
        return {
            triggered: true,
            loading_flag: false,
            loading_ico_flag: false,
            loading_str: '玩命加载中',
            color: '',
            rgbcolor: '',
            LIST: [],
            li_nodata: false,
            banner: '',
            nTitle: '',
            SHARE: '',
            backtop_flag: false,
            pages: [],
            nTop: '',
            scrolltopNum_index: 0,
            trend_idx: 0,
            dl: [],
            trend_idx2: 0
        };
    },
    onLoad: function (t) {
        var that = this;
        app.globalData.get_config('_ZEAI').then(function (t) {
            that.setData({
                color: app.globalData._ZEAI.color,
                rgbcolor: e.c16_rgb(app.globalData._ZEAI.color)
            });
        });
        app.globalData.get_navigationBarTopHeight(this);
        app.globalData.get_openid().then(function (t) {
            that.init();
        });
    },
    onPullDownRefresh: function () {
        var that = this;
        uni.vibrateShort({
            type: 'heavy'
        });
        setTimeout(function () {
            that.setData({
                triggered: false,
                loading_flag: false,
                loading_str: '玩命加载中',
                LIST: [],
                li_nodata: false
            });
            that.setloading('end', '玩命加载中');
            n = 2;
            that.init();
        }, 500);
    },
    onReachBottom: function () {
        var e = this.LIST;
        var that = this;
        if (o) {
            o = false;
            that.setloading('start', '玩命加载中');
            var s = {
                submitok: 'list',
                p: n,
                openid: t.openid
            };
            app.globalData.ajax({
                url: 'anli.php',
                data: s,
                success: function (t) {
                    if (1 == t.flag) {
                        var i = e.length;
                        if (t.LIST.length < 1) {
                            that.setloading('end', '已全部加载完毕');
                            return void (o = false);
                        }
                        that.setData(a({}, 'LIST[' + i + ']', t.LIST));
                        n += 1;
                        o = true;
                    } else {
                        uni.showToast({
                            title: t.msg,
                            icon: 'none',
                            mask: true
                        });
                    }
                    that.setloading('end', '上拉加载更多');
                }
            });
        }
    },
    onShareAppMessage: function () {
        return {
            imageUrl: this.SHARE.imgurl,
            title: this.SHARE.content,
            path: '/pagesA/anli/anli'
        };
    },
    onShareTimeline: function () {
        return {
            imageUrl: this.SHARE.imgurl,
            title: this.SHARE.content,
            query: '',
            path: '/pagesA/anli/anli'
        };
    },
    methods: {
        init: function () {
            var that = this;
            uni.showLoading({
                title: '玩命加载中...',
                mask: true
            });
            uni.showNavigationBarLoading();
            o = false;
            t = uni.getStorageSync('COOK_U');
            app.globalData.ajax({
                url: 'anli.php',
                data: {
                    submitok: 'list',
                    openid: t.openid
                },
                success: function (t) {
                    uni.setNavigationBarTitle({
                        title: t.nTitle
                    });
                    that.setData({
                        banner: t.banner,
                        nTitle: t.nTitle,
                        SHARE: t.SHARE
                    });
                    if (1 == t.flag) {
                        if (0 == t.LIST.length) {
                            that.setData({
                                LIST: [],
                                li_nodata: true
                            });
                        } else {
                            that.setData(a({}, 'LIST[0]', t.LIST));
                        }
                    } else {
                        uni.showToast({
                            title: t.msg,
                            icon: 'none',
                            mask: true
                        });
                    }
                    o = true;
                    uni.hideLoading();
                    uni.hideNavigationBarLoading();
                }
            });
        },

        zoom9Fn: function (t) {
            var a = t.currentTarget.dataset.cur;
            a = a.replace('_s.', '_b.');
            var i = t.currentTarget.dataset.idx;
            var n = t.currentTarget.dataset.idx2;
            var o = this.LIST[i][n].piclist.map(function (t, a) {
                return t.replace('_s.', '_b.');
            });
            e.empty(a) ||
                uni.previewImage({
                    current: a,
                    urls: o
                });
        },

        uidFn: function (t) {
            var a = t.currentTarget.dataset.uid;
            uni.navigateTo({
                url: '/pagesA/u/u?uid=' + a
            });
        },

        agreeFn: function (n) {
            var that = this;
            var r = n.currentTarget.dataset.idx;
            var s = n.currentTarget.dataset.idx2;
            var l = n.currentTarget.dataset.id;
            app.globalData.chklogin().then(function (n) {
                n
                    ? ((t = uni.getStorageSync('COOK_U')),
                      app.globalData.ajax({
                          url: 'anli.php',
                          data: {
                              submitok: 'ajax_agree',
                              tid: l,
                              openid: t.openid
                          },
                          success: function (t) {
                              if (1 == t.flag) {
                                  var i;
                                  var n = that.LIST[r][s].agree.ulist.length;
                                  that.setData(
                                      (a((i = {}), 'LIST[' + r + '][' + s + '].agree.fly', 'block'),
                                      a(i, 'LIST[' + r + '][' + s + '].agree.class', ' ed'),
                                      a(i, 'LIST[' + r + '][' + s + '].agree.num', t.num),
                                      a(i, 'LIST[' + r + '][' + s + '].agree.ulist[' + n + ']', {
                                          uid: t.uid,
                                          photo_s_url: t.photo_s_url
                                      }),
                                      i)
                                  );
                              } else {
                                  t.this = that;
                                  t.url = 'no';
                                  e.sorry(t);
                              }
                          }
                      }))
                    : uni.navigateTo({
                          url: '/pages/login/login'
                      });
            });
        },

        setloading: function (t, a) {
            'start' == t
                ? this.setData({
                      loading_flag: true,
                      loading_ico_flag: true,
                      loading_str: a
                  })
                : this.setData({
                      loading_flag: false,
                      loading_ico_flag: false,
                      loading_str: a
                  });
        },

        binnd_scroll: function (t) {
            t.detail.scrollTop > 100
                ? this.setData({
                      backtop_flag: true
                  })
                : this.setData({
                      backtop_flag: false
                  });
        },

        backtopFn: function (t) {
            var e = 'scrolltopNum_' + t.currentTarget.dataset.id;
            this.setData(a({}, e, 0));
        },

        onPullDownRefresh() {
            console.log('占位：函数 onPullDownRefresh 未声明');
        },

        onReachBottom() {
            console.log('占位：函数 onReachBottom 未声明');
        },

        nodatabackFn() {
            console.log('占位：函数 nodatabackFn 未声明');
        }
    }
};
</script>
<style>
@import 'anli.css';
</style>
